import 'dart:math';

import 'package:flutter/material.dart';
import 'package:kasax_demos2/entry/data_posts_test.dart';
import 'package:kasax_demos2/pratacties/douban/entrys/wmdb_film_result_entity.dart';

class PageMovieDetails extends StatefulWidget {
  final WmdbFilmResultEntity entity;

  const PageMovieDetails(this.entity, {Key? key}) : super(key: key);

  @override
  _MoveDetailsState createState() => _MoveDetailsState();
}

class _MoveDetailsState extends State<PageMovieDetails> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            backgroundColor: Colors.green,
            expandedHeight: 215,
            stretch: true,
            flexibleSpace: FlexibleSpaceBar(
              title: Text("${widget.entity.data[0].name}"),
              background: buildBgImg(),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.only(top: 18, bottom: 18, right: 15, left: 15),
            sliver: SliverList(
                delegate: SliverChildBuilderDelegate((context, index) {
              return Container(
                child: Column(
                  children: [
                    Text(
                      "${widget.entity.data[0].description}",
                      style: TextStyle(
                          letterSpacing: 3,
                          wordSpacing: 2,
                          fontWeight: FontWeight.w300,
                          fontSize: 18),
                    )
                  ],
                ),
              );
            }, childCount: 1)),
          )
        ],
      ),
    );
  }

  Widget buildBgImg() {
    var imgUrl =
        PostsDatas.TEST_POSTS[Random().nextInt(PostsDatas.TEST_POSTS.length)].imageUrl;
    print("imagurl: $imgUrl");
    return Stack(
      fit: StackFit.expand,
      children: [
        Image(
          fit: BoxFit.cover,
          image: NetworkImage("$imgUrl"),
        ),
        // 阴影效果添加
        const DecoratedBox(
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [Color(0x60000000), Color(0x00000000)],
                    begin: Alignment(0.0, 0.5),
                    end: Alignment(0.0, 0.0))))
      ],
    );
  }
}
